<?php
// 这是系统自动生成的公共文件
//获取登录session信息
use think\facade\Session;

function get_admin_session(){
    return Session::get('name');
}

function clear_admin_session(){
    Session::delete('name');
}

//去除回车，空格，将字符串转换为数组
function textareaToStr($str){
    //去除两边空格，
    $qian=array("\t","\n","\r");
    $strNow = str_replace($qian, ',', $str);
    $arr = explode(',',$strNow);
    //去除数组两边空格
    foreach ($arr as $k=>$v){
        $arr[$k] = str_replace(array("/r/n", "/r", "/n"," ","  ",""), "", trim($v));
        if ($v==""){
            unset($arr[$k]);
        }
    }
    return $arr;
}


/**
 * layui输出信息
 */
function lay_msg($code="1",$msg="",$count="",$data=[]){

    $arr=array();
    $arr['code'] = $code;
    $arr['msg'] = $msg;
    $arr['count'] = $count;
    $arr['data'] = $data;
    return json($arr);

}


/**
 * @param $str  2019-10-01 00:00:00 - 2019-10-04 00:00:00
 * @return array bTime 开始时间  eTime 结束时间
 */
function cut_time($str){
//    var_dump($str);
//       $str = '2019-10-01 00:00:00 - 2019-10-04 00:00:00';
    //将字符串分割成两个数组
    $arr = explode(' - ',$str);
    //将时间转换为时间戳
    $arr_time = [
        'bTime'=>strtotime($arr['0']),
        'eTime'=>strtotime($arr['1'])
    ];
    return $arr_time;
}
